
---------------------------------------------------------------------------------------
-- RTBB_BridgeBoard Init Script
---------------------------------------------------------------------------------------

-- This file must be loaded after the init_base.lua ;

require "RTBBLua"

g_hBridgeBoard = NULL

---------------------------------------------------------------------------------------

function open_bridgeboard(index)
	g_hBridgeBoard = RTBB_ConnectToBridgeByIndex(index);

	if( g_hBridgeBoard == nil )
	then
		dbgprintf( "Connect RTBridgeBoard failed.\n");
		return false;
	end

	return true;
end

function enum_bridgeboard()

	local hEnum = RTBB_EnumBoard();

	if hEnum == nil then
		dbgprintf ("RTBB_EnumBoard faled!\n");
		return false;
	end

	nCount = RTBB_GetBoardCount(hEnum);
	dbgprintf ( "%d board(s) found!\n", nCount );

	for i = 0, nCount-1, 1 do
		dbgprintf ( "board%d information ==>\n", i );

		local info = RTBB_GetEnumBoardInfo( hEnum, i );

		dbgprintf( "VenderName = %s\n", RTBB_BIGetVenderName(info) );
		dbgprintf( "ControllerName = %s\n", RTBB_BIGetControllerName(info) );
		dbgprintf( "LibraryName = %s\n", RTBB_BIGetLibraryName(info) );
		dbgprintf( "LibraryPath = %s\n", RTBB_BIGetLbraryPath(info) );
		dbgprintf( "FirmwareInfo = %s\n", RTBB_BIGetFirmwareInfo(info) );
		dbgprintf( "DevicePath = %s\n", RTBB_BIGetDevicePath(info) );
		dbgprintf( "BoardName = %s\n\n", RTBB_BIGetBoardName(info) );

		dbgprintf( "Index = %d\n", RTBB_BIGetIndexOfDevice(info) );
		dbgprintf( "VID = 0x%x , PID = 0x%x\n", RTBB_BIGetVID(info), RTBB_BIGetPID(info) );
		dbgprintf( "Capability = %d\n", RTBB_BIGetCapability(info) );
		dbgprintf( "GPIOBitsType = %d\n", RTBB_BIGetGPIOBitsType(info) );
		dbgprintf( "GPIOCount = %d\n", RTBB_BIGetGPIOPinCount(info) );
		dbgprintf( "I2CCount = %d\n", RTBB_BIGetI2CCount(info) );
		dbgprintf( "SPICount = %d\n", RTBB_BIGetSPICount(info) );
		dbgprintf( "UartCount = %d\n", RTBB_BIGetUARTCount(info) );
	end

	return RTBB_FreeEnumBoard( hEnum );
end

---------------------------------------------------------------------------------------

function init_module_board()

	local bInitDone = true

	-- if( bInitDone ) then bInitDone = enum_bridgeboard() end

	if( bInitDone )
	then
		bInitDone = open_bridgeboard(0)
	end

	return bInitDone
end






